
public class Obhod {

	private static int[][] array = {
		{1,   2,  3,  4, 5},
		{16, 17, 18, 19, 6},
		{15, 24, 25, 20, 7},
		{14, 23, 22, 21, 8},
		{13, 12, 11, 10, 9}}; 


	public static void main(String[] args) {
		obhod();
	}


	private static void obhod() {
		int rows = 5;
		int cols = 5;
		int curRow = 0;
		int curCol = 0;
		int offSetRow = 0;
		int offSetCol = 0;
		do{
			for(curCol = offSetCol; curCol < cols; curCol++){
				System.out.print(array[curRow][curCol] + " ");
			}
			curCol--;
			for(curRow = offSetRow + 1; curRow < rows; curRow++){
				System.out.print(array[curRow][curCol] + " ");
			}
			curRow--;
			for(curCol = curCol - 1; curCol >= offSetCol; curCol--){
				System.out.print(array[curRow][curCol] + " ");
			}
			curCol++;

			for(curRow = curRow - 1; curRow > offSetRow; curRow--){
				System.out.print(array[curRow][curCol] + " ");
			}
			curRow++;
			
			rows--;
			cols--;
			offSetRow++;
			offSetCol++;
		}while((cols > curCol)||(rows > curRow));

	}


}
